<template>
  <div class="home">
    <div class="left">
      <div class="prj-name">Crossing the Dimensional Wall</div>
      <div class="cover">
        <img class="image" src="@/assets/img/home/home-bg.jpeg" alt="" />
      </div>
    </div>
    <div class="right">
      <div class="top">
        <div class="tab-bar">
          <div class="primary">
            主题
            <div class="btn" @click="onChangePrimary(blackTheme)">默认</div>
            <div class="btn" @click="onChangePrimary(whiteTheme)">白色</div>
            <div class="btn" @click="onChangePrimary(pinkTheme)">粉色</div>
            <div class="btn" @click="onChangePrimary(purpleTheme)">紫色</div>
            <div class="btn" @click="onChangePrimary(brownTheme)">棕黑</div>
          </div>
          <div class="login-out" @click="onLoginOut">
            退出登录
            <el-icon><SwitchButton /></el-icon>
          </div>
        </div>
      </div>
      <div class="main">
        <el-upload
          class="upload"
          drag
          action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
          multiple
          :on-change="onFileChange"
        >
          <el-icon class="el-icon--upload"><upload-filled /></el-icon>
          <div class="el-upload__text">
            拖拽文件到此处 <em>或者点击上传文件</em>
          </div>
          <template #tip>
            <div class="el-upload__tip">jpg/png 文件大小不超过500kb</div>
          </template>
        </el-upload>
      </div>
    </div>
  </div>
</template>

<script setup>
import { UploadFilled } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";

// 主题换肤
const blackTheme = {
  "--primary-bgc": "#1b1819",
  "--primary-text-color": "#fff",
};

const whiteTheme = {
  "--primary-bgc": "#eee",
  "--primary-text-color": "#333",
};

const pinkTheme = {
  "--primary-bgc": "#ffb3a7",
  "--primary-text-color": "#fff",
};

const purpleTheme = {
  "--primary-bgc": "#815476",
  "--primary-text-color": "#fff",
};

const brownTheme = {
  "--primary-bgc": "#312520",
  "--primary-text-color": "#fff",
};

function onChangePrimary(auTheme) {
  console.log("first");
  // 修改变量 --primary-color 以实现换肤
  let docEle = document.documentElement;

  // 批量覆盖样式
  for (const key in auTheme) {
    if (auTheme.hasOwnProperty(key)) {
      const value = auTheme[key];
      // 关键
      docEle.style.setProperty(key, value);
    }
  }
  // 释放内存，避免内存溢出
  docEle = null;
}

// 退出登录功能
const router = useRouter();
function onLoginOut() {
  localStorage.removeItem("token");
  router.push("/login");
}

function onFileChange(file) {
  setTimeout(() => {
    router.push(`/show/${file.name}`);
  }, 1000);
}
</script>

<style lang="less" scoped>
.home {
  display: flex;
  // background-color: #eee;
  background-color: var(--primary-bgc);

  .left,
  .right {
    width: 50%;
    height: 100vh;
  }

  .left {
    .prj-name {
      width: 640px;
      height: 200px;
      margin: 0 auto;
      margin-top: 70px;
      color: var(--primary-text-color);
      font-size: 72px;
      text-align: center;
      font-weight: 700;
    }

    .cover {
      width: 640px;
      margin: 0 auto;

      .image {
        width: 100%;
      }
    }
  }

  .right {
    height: 100px;
    color: var(--primary-text-color);

    .top {
      margin: 40px 0;
      height: 80px;

      .tab-bar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 80px;
        font-size: 24px;

        .primary {
          flex: 1;
          display: flex;
          align-items: center;

          .btn {
            margin-left: 10px;
            font-size: 14px;
            cursor: pointer;
          }
        }

        .login-out {
          display: flex;
          align-items: center;
          width: 120px;
          padding: 0 20px;
          cursor: pointer;
        }
      }
    }

    .main {
      width: 400px;
      height: 400px;
      margin: 0 auto;
      margin-top: 90px;

      :deep(.el-upload-dragger) {
        height: 400px;
        margin: auto 0;

        .el-icon {
          margin-top: 100px;
        }
      }
      :deep(.el-upload__tip) {
        color: var(--primary-text-color);
      }
    }
  }
}
</style>
